home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / dist / sdbout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-07  |  24.9 KB  |  962 lines

  1. /* Output sdb-format symbol table information from GNU compiler.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22.  
  23. #ifdef SDB_DEBUGGING_INFO
  24.  
  25. #include "tree.h"
  26. #include "rtl.h"
  27. #include <stdio.h>
  28. #include <syms.h>
  29. /* #include <storclass.h>  used to be this instead of syms.h.  */
  30.  
  31. /* Line number of beginning of current function, minus one.  */
  32.  
  33. int sdb_begin_function_line = 0;
  34.  
  35. /* Counter to generate unique "names" for nameless struct members.  */
  36.  
  37. static int unnamed_struct_number = 0;
  38.  
  39. extern FILE *asm_out_file;
  40.  
  41. extern tree current_function_decl;
  42.  
  43. void sdbout_init ();
  44. void sdbout_symbol ();
  45. void sdbout_tags();
  46. void sdbout_types();
  47.  
  48. static void sdbout_syms ();
  49. static void sdbout_one_type ();
  50. static int plain_type_1 ();
  51.  
  52. /* Random macros describing parts of SDB data.  */
  53.  
  54. /* Put something here if lines get too long */
  55. #define CONTIN
  56.  
  57. #ifndef PUT_SDB_SCL
  58. #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d;", (a))
  59. #endif
  60.  
  61. #ifndef PUT_SDB_INT_VAL
  62. #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d;", (a))
  63. #endif
  64.  
  65. #ifndef PUT_SDB_VAL
  66. #define PUT_SDB_VAL(a)                \
  67. ( fputs ("\t.val\t", asm_out_file),        \
  68.   output_addr_const (asm_out_file, (a)),    \
  69.   fputc (';', asm_out_file))
  70. #endif
  71.  
  72. #ifndef PUT_SDB_DEF
  73. #define PUT_SDB_DEF(a)                \
  74. do { fprintf (asm_out_file, "\t.def\t");    \
  75.      ASM_OUTPUT_LABELREF (asm_out_file, a);     \
  76.      fprintf (asm_out_file, ";"); } while (0)
  77. #endif
  78.  
  79. #ifndef PUT_SDB_PLAIN_DEF
  80. #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s;",a)
  81. #endif
  82.  
  83. #ifndef PUT_SDB_ENDEF
  84. #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
  85. #endif
  86.  
  87. #ifndef PUT_SDB_TYPE
  88. #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o;", a)
  89. #endif
  90.  
  91. #ifndef PUT_SDB_SIZE
  92. #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d;", a)
  93. #endif
  94.  
  95. #ifndef PUT_SDB_DIM
  96. #define PUT_SDB_DIM(a) fprintf(asm_out_file, "\t.dim\t%d;", a)
  97. #endif
  98.  
  99. #ifndef PUT_SDB_TAG
  100. #define PUT_SDB_TAG(a)                \
  101. do { fprintf (asm_out_file, "\t.tag\t");    \
  102.      ASM_OUTPUT_LABELREF (asm_out_file, a);    \
  103.      fprintf (asm_out_file, ";"); } while (0)
  104. #endif
  105.  
  106. #ifndef PUT_SDB_BLOCK_START
  107. #define PUT_SDB_BLOCK_START(LINE)        \
  108.   fprintf (asm_out_file,            \
  109.        "\t.def\t.bb;\t.val\t.;\t.scl\t100;\t.line\t%d;\t.endef\n",    \
  110.        (LINE))
  111. #endif
  112.  
  113. #ifndef PUT_SDB_BLOCK_END
  114. #define PUT_SDB_BLOCK_END(LINE)            \
  115.   fprintf (asm_out_file,            \
  116.        "\t.def\t.eb;.val\t.;\t.scl\t100;\t.line\t%d;\t.endef\n",    \
  117.        (LINE))
  118. #endif
  119.  
  120. #ifndef PUT_SDB_FUNCTION_START
  121. #define PUT_SDB_FUNCTION_START(LINE)        \
  122.   fprintf (asm_out_file,            \
  123.        "\t.def\t.bf;\t.val\t.;\t.scl\t101;\t.line\t%d;\t.endef\n",    \
  124.        (LINE))
  125. #endif
  126.  
  127. #ifndef PUT_SDB_FUNCTION_END
  128. #define PUT_SDB_FUNCTION_END(LINE)        \
  129.   fprintf (asm_out_file,            \
  130.        "\t.def\t.ef;\t.val\t.;\t.scl\t101;\t.line\t%d;\t.endef\n",    \
  131.        (LINE))
  132. #endif
  133.  
  134. #ifndef PUT_SDB_EPILOGUE_END
  135. #define PUT_SDB_EPILOGUE_END(NAME)        \
  136.   fprintf (asm_out_file,            \
  137.        "\t.def\t%s;\t.val\t.;\t.scl\t-1;\t.endef\n",    \
  138.        (NAME))
  139. #endif
  140.  
  141. #ifndef SDB_GENERATE_FAKE
  142. #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
  143.   sprintf ((BUFFER), ".%dfake", (NUMBER));
  144. #endif
  145.  
  146. /* Return the sdb tag identifier string for TYPE
  147.    if TYPE has already been defined; otherwise return a null pointer.   */
  148.   
  149. #define KNOWN_TYPE_TAG(type) (char *)(TYPE_SYMTAB_ADDRESS (type))
  150.  
  151. /* Set the sdb tag identifier string for TYPE to NAME.  */
  152.  
  153. #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
  154.   (TYPE_SYMTAB_ADDRESS (TYPE) = (int)(NAME))
  155.  
  156. /* Return the name (a string) of the struct, union or enum tag
  157.    described by the TREE_LIST node LINK.  This is 0 for an anonymous one.  */
  158.  
  159. #define TAG_NAME(link) \
  160.   (((link) && TREE_PURPOSE ((link)) \
  161.     && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
  162.    ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
  163.  
  164. /* Ensure we don't output a negative line number.  */
  165. #define MAKE_LINE_SAFE(line)  \
  166.   if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
  167.  
  168. /* Tell the assembler the source file name.
  169.    On systems that use SDB, this is done whether or not -g,
  170.    so it is called by ASM_FILE_START.
  171.  
  172.    ASM_FILE is the assembler code output file,
  173.    INPUT_NAME is the name of the main input file.  */
  174.  
  175. void
  176. sdbout_filename (asm_file, input_name)
  177.      FILE *asm_file;
  178.      char *input_name;
  179. {
  180.   int len = strlen (input_name);
  181.   char *na = input_name + len;
  182.  
  183.   /* NA gets INPUT_NAME sans directory names.  */
  184.   while (na > input_name)
  185.     {
  186.       if (na[-1] == '/')
  187.     break;
  188.       na--;
  189.     }
  190.  
  191. #ifdef ASM_OUTPUT_SOURCE_FILENAME
  192.   ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
  193. #else
  194.   fprintf (asm_file, "\t.file\t\"%s\"\n", na);
  195. #endif
  196. }
  197.  
  198. /* Set up for SDB output at the start of compilation.  */
  199.  
  200. void
  201. sdbout_init ()
  202. {
  203.   /* Output all the initial permanent types.  */
  204.   sdbout_types (nreverse (get_permanent_types ()));
  205. }
  206.  
  207. #if 0
  208.  
  209. /* return the tag identifier for type
  210.  */
  211.  
  212. {
  213. char *
  214. tag_of_ru_type (type,link)
  215.      tree type,link;
  216. {
  217.   if (TYPE_SYMTAB_ADDRESS (type))
  218.     return (char *)TYPE_SYMTAB_ADDRESS (type);
  219.   if (link &&
  220.       TREE_PURPOSE (link)
  221.       && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
  222.     TYPE_SYMTAB_ADDRESS (type) =
  223.       (int)IDENTIFIER_POINTER (TREE_PURPOSE (link));
  224.   else
  225.     return (char *) TYPE_SYMTAB_ADDRESS (type);
  226. }
  227. #endif
  228.  
  229. /* Return a unique string to name an anonymous type.  */
  230.  
  231. static char *
  232. gen_fake_label ()
  233. {
  234.   char label[10];
  235.   char *labelstr;
  236.   SDB_GENERATE_FAKE (label, unnamed_struct_number);
  237.   unnamed_struct_number++;
  238.   labelstr = (char *) permalloc (strlen (label) + 1);
  239.   strcpy (labelstr, label);
  240.   return labelstr;
  241. }
  242.  
  243. /* Return the number which describes TYPE for SDB.
  244.    For pointers, etc., this function is recursive.
  245.    Each record, union or enumeral type must already have had a
  246.    tag number output.  */
  247.  
  248. /* The number is given by d6d5d4d3d2d1bbbb 
  249.    where bbbb is 4 bit basic type, and di indicate  one of notype,ptr,fn,array.
  250.    Thus, char *foo () has bbbb=T_CHAR
  251.               d1=D_FCN
  252.               d2=D_PTR
  253.  N_BTMASK=     017       1111     basic type field.
  254.  N_TSHIFT=       2                derived type shift
  255.  N_BTSHFT=       4                Basic type shift */
  256.  
  257. /* Produce the number that describes a pointer, function or array type.
  258.    PREV is the number describing the target, value or element type.
  259.    DT_type describes how to transform that type.  */
  260. #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
  261.   ((((PREV)&~N_BTMASK)<<N_TSHIFT)|(DT_type<<N_BTSHFT)|(PREV&N_BTMASK))
  262.  
  263. static int
  264. plain_type (type)
  265.      tree type;
  266. {
  267.   int val = plain_type_1 (type);
  268.   if (TREE_CODE (type) == ARRAY_TYPE)
  269.     {
  270.       int size = int_size_in_bytes (type);
  271.       /* Don't kill sdb if type is not laid out or has variable size.  */
  272.       if (size < 0)
  273.     size = 0;
  274.       PUT_SDB_SIZE (size);
  275.     }
  276.   return val;
  277. }
  278.  
  279. static void
  280. sdbout_record_type_name (type)
  281.      tree type;
  282. {
  283.   char *name = 0;
  284.  
  285.   if (KNOWN_TYPE_TAG (type))
  286.     return;
  287.  
  288.   if (TYPE_NAME (type) != 0) 
  289.     {
  290.       tree t = 0;
  291.       /* Find the IDENTIFIER_NODE for the type name.  */
  292.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  293.     {
  294.       t = TYPE_NAME (type);
  295.     }
  296.       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  297.     {
  298.       t = DECL_NAME (TYPE_NAME (type));
  299.     }
  300.  
  301.       /* Now get the name as a string, or invent one.  */
  302.       if (t != 0)
  303.     name = IDENTIFIER_POINTER (t);
  304.     }
  305.  
  306.   if (name == 0)
  307.     name = gen_fake_label ();
  308.  
  309.   SET_KNOWN_TYPE_TAG (type, name);
  310. }
  311.  
  312. static int
  313. plain_type_1 (type)
  314.      tree type;
  315. {
  316.   if (type == 0)  
  317.     type = void_type_node;
  318.   if (type == error_mark_node)
  319.     type = integer_type_node;
  320.   type = TYPE_MAIN_VARIANT (type);
  321.  
  322.   switch (TREE_CODE (type))
  323.     {
  324.     case VOID_TYPE:
  325.       return T_INT;
  326.     case INTEGER_TYPE:
  327.       switch (int_size_in_bytes (type))
  328.     {
  329.     case 4:
  330.       return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
  331.     case 1:
  332.       return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
  333.     case 2:
  334.       return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
  335.     default:
  336.       return 0;
  337.     }
  338.     case REAL_TYPE:
  339.       switch (int_size_in_bytes (type))
  340.     {
  341.     case 4:
  342.       return T_FLOAT;
  343.     default:
  344.       return T_DOUBLE;
  345.     }
  346.     case ARRAY_TYPE:
  347.       {
  348.     int m = plain_type (TREE_TYPE (type));
  349.     PUT_SDB_DIM (TYPE_DOMAIN (type)
  350.              ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
  351.              : 0);
  352.     return PUSH_DERIVED_LEVEL (DT_ARY, m);
  353.       }
  354.     case RECORD_TYPE:
  355.     case UNION_TYPE:
  356.     case ENUMERAL_TYPE:
  357.       {
  358.     char *tag;
  359.     int size;
  360.     sdbout_record_type_name (type);
  361.     if (TREE_ASM_WRITTEN (type))
  362.       {
  363.         /* Output the referenced structure tag name
  364.            only if the .def has already been output.
  365.            At least on 386, the Unix assembler
  366.            cannot handle forward references to tags.  */
  367.         tag = KNOWN_TYPE_TAG (type);
  368.         PUT_SDB_TAG (tag);
  369.       }
  370.     size = int_size_in_bytes (type);
  371.     if (size < 0)
  372.       size = 0;
  373.     PUT_SDB_SIZE (size);
  374.     return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
  375.         : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
  376.         : T_ENUM);
  377.       }
  378.     case POINTER_TYPE:
  379.     case REFERENCE_TYPE:
  380.       {
  381.     int m = plain_type (TREE_TYPE (type));
  382.     return PUSH_DERIVED_LEVEL (DT_PTR, m);
  383.       }
  384.     case FUNCTION_TYPE:
  385.     case METHOD_TYPE:
  386.       {
  387.     int m = plain_type (TREE_TYPE (type));
  388.     return PUSH_DERIVED_LEVEL (DT_FCN, m);
  389.       }
  390.     default:
  391.       return 0;
  392.     }
  393. }
  394.  
  395. /* Output the symbols defined in block number DO_BLOCK.
  396.    Set NEXT_BLOCK_NUMBER to 0 before calling.
  397.  
  398.    This function works by walking the tree structure,
  399.    counting blocks, until it finds the desired block.  */
  400.  
  401. static int do_block = 0;
  402.  
  403. static int next_block_number;
  404.  
  405. static void
  406. sdbout_block (stmt)
  407.      register tree stmt;
  408. {
  409.   while (stmt)
  410.     {
  411.       switch (TREE_CODE (stmt))
  412.     {
  413.     case COMPOUND_STMT:
  414.     case LOOP_STMT:
  415.       sdbout_block (STMT_BODY (stmt));
  416.       break;
  417.  
  418.     case IF_STMT:
  419.       sdbout_block (STMT_THEN (stmt));
  420.       sdbout_block (STMT_ELSE (stmt));
  421.       break;
  422.  
  423.     case LET_STMT:
  424.       /* Ignore LET_STMTs for blocks never really used to make RTL.  */
  425.       if (! TREE_USED (stmt))
  426.         break;
  427.       /* When we reach the specified block, output its symbols.  */
  428.       if (next_block_number == do_block)
  429.         {
  430.           sdbout_tags (STMT_TYPE_TAGS (stmt));
  431.           sdbout_syms (STMT_VARS (stmt));
  432.         }
  433.  
  434.       /* If we are past the specified block, stop the scan.  */
  435.       if (next_block_number > do_block)
  436.         return;
  437.  
  438.       next_block_number++;
  439.  
  440.       /* Scan the blocks within this block.  */
  441.       sdbout_block (STMT_SUBBLOCKS (stmt));
  442.     }
  443.       stmt = TREE_CHAIN (stmt);
  444.     }
  445. }
  446.  
  447. /* Call sdbout_symbol on each decl in the chain SYMS.  */
  448.  
  449. static void
  450. sdbout_syms (syms)
  451.      tree syms;
  452. {
  453.   while (syms)
  454.     {
  455.       sdbout_symbol (syms, 1);
  456.       syms = TREE_CHAIN (syms);
  457.     }
  458. }
  459.  
  460. /* Output SDB information for a symbol described by DECL.
  461.    LOCAL is nonzero if the symbol is not file-scope.  */
  462.  
  463. void
  464. sdbout_symbol (decl, local)
  465.      tree decl;
  466.      int local;
  467. {
  468.   int letter = 0;
  469.   tree type = TREE_TYPE (decl);
  470.  
  471.   /* If global, first output all types and all
  472.      struct, enum and union tags that have been created
  473.      and not yet output.  */
  474.  
  475.   if (local == 0)
  476.     {
  477.       sdbout_tags (gettags ());
  478.       sdbout_types (nreverse (get_permanent_types ()));
  479.     }
  480.  
  481.   switch (TREE_CODE (decl))
  482.     {
  483.     case CONST_DECL:
  484.       /* Enum values are defined by defining the enum type.  */
  485.       return;
  486.  
  487.     case FUNCTION_DECL:
  488.       if (TREE_EXTERNAL (decl))
  489.     return;
  490.       if (GET_CODE (DECL_RTL (decl)) != MEM
  491.       || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
  492.     return;
  493.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  494.       PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  495.       PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
  496.       break;
  497.  
  498.     case TYPE_DECL:
  499.       /* Output typedef name.  */
  500.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  501.       PUT_SDB_SCL (C_TPDEF);
  502.       break;
  503.       
  504.     case PARM_DECL:
  505.       /* Parm decls go in their own separate chains
  506.      and are output by sdbout_reg_parms and sdbout_parms.  */
  507.       abort ();
  508.  
  509.     case VAR_DECL:
  510.       /* Don't mention a variable that is external.
  511.      Let the file that defines it describe it.  */
  512.       if (TREE_EXTERNAL (decl))
  513.     return;
  514.  
  515.       /* Don't mention a variable at all
  516.      if it was completely optimized into nothingness.  */
  517.       if (GET_CODE (DECL_RTL (decl)) == REG
  518.       && (REGNO (DECL_RTL (decl)) < 0
  519.           || REGNO (DECL_RTL (decl)) >= FIRST_PSEUDO_REGISTER))
  520.     return;
  521.  
  522.       /* Ok, start a symtab entry and output the variable name.  */
  523.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  524.  
  525.       if (GET_CODE (DECL_RTL (decl)) == MEM
  526.       && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
  527.     {
  528.       if (TREE_PUBLIC (decl))
  529.         {
  530.           PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  531.               PUT_SDB_SCL (C_EXT);
  532.         }
  533.       else
  534.         {
  535.           PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  536.               PUT_SDB_SCL (C_STAT);
  537.         }
  538.     }
  539.       else if (GET_CODE (DECL_RTL (decl)) == REG)
  540.     {
  541.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl))));
  542.       PUT_SDB_SCL (C_REG);
  543.     }
  544.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  545.            && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
  546.            || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
  547.                && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
  548.     /* If the value is indirect by memory or by a register
  549.        that isn't the frame pointer
  550.        then it means the object is variable-sized and address through
  551.        that register or stack slot.  DBX has no way to represent this
  552.        so all we can do is output the variable as a pointer.  */
  553.     {
  554.       if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
  555.         {
  556.           PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl))));
  557.           PUT_SDB_SCL (C_REG);
  558.         }
  559.       else
  560.         {
  561.           /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
  562.          (CONST_INT...)))).
  563.          We want the value of that CONST_INT.  */
  564.           /* Encore compiler hates a newline in a macro arg, it seems.  */
  565.           PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (XEXP (DECL_RTL (decl), 0), 0), 1)));
  566.           PUT_SDB_SCL (C_AUTO);
  567.         }
  568.  
  569.       type = build_pointer_type (TREE_TYPE (decl));
  570.     }
  571.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  572.            && GET_CODE (XEXP (DECL_RTL (decl), 0)) == PLUS
  573.            && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG
  574.            && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 1)) == CONST_INT)
  575.     {
  576.       /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
  577.          We want the value of that CONST_INT.  */
  578.       PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1)));
  579.       PUT_SDB_SCL (C_AUTO);
  580.     }
  581.       else
  582.     {
  583.       /* It is something we don't know how to represent for SDB.  */
  584.     }
  585.       break;
  586.     }
  587.   PUT_SDB_TYPE (plain_type (type));
  588.   PUT_SDB_ENDEF;
  589. }
  590.  
  591. /* Given a list of TREE_LIST nodes that point at types,
  592.    output those types for SDB.
  593.    We must check to include those that have been mentioned already with
  594.    only a cross-reference.  */
  595.  
  596. void
  597. sdbout_tags (tags)
  598.      tree tags;
  599. {
  600.   register tree link;
  601.  
  602.   for (link = tags; link; link = TREE_CHAIN (link))
  603.     {
  604.       register tree type = TREE_VALUE (link);
  605.  
  606.       if (TREE_PURPOSE (link) != 0
  607.       && TYPE_SIZE (type) != 0)
  608.     sdbout_one_type (type);
  609.     }
  610. }
  611.  
  612. /* Given a chain of ..._TYPE nodes, all of which have names,
  613.    output definitions of those names, as typedefs.  */
  614.  
  615. void
  616. sdbout_types (types)
  617.      register tree types;
  618. {
  619.   register tree link;
  620.  
  621.   for (link = types; link; link = TREE_CHAIN (link))
  622.     sdbout_one_type (link);
  623. }
  624.  
  625. static void
  626. sdbout_type (type)
  627.      tree type;
  628. {
  629.   register tree tem;
  630.   if (type == error_mark_node)
  631.     type = integer_type_node;
  632.   PUT_SDB_TYPE (plain_type (type));
  633. }
  634.  
  635. /* Output types of the fields of type TYPE, if they are structs.
  636.    Don't chase through pointer types, since that could be circular.
  637.    They must come before TYPE, since forward refs are not allowed.
  638.  
  639.    This is not actually used, since the COFF assembler rejects the
  640.    results.  No one knows why it rejects them.  */
  641.  
  642. static void
  643. sdbout_field_types (type)
  644.      tree type;
  645. {
  646.   tree tail;
  647.   for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
  648.     sdbout_one_type (TREE_TYPE (tail));
  649. }
  650.  
  651. /* Use this to put out the top level defined record and union types
  652.    for later reference.  If this is a struct with a name, then put that
  653.    name out.  Other unnamed structs will have .xxfake labels generated so
  654.    that they may be referred to later.
  655.    The label will be stored in the KNOWN_TYPE_TAG slot of a type.
  656.    It may NOT be called recursively.  */
  657.  
  658. static void
  659. sdbout_one_type (type)
  660.      tree type;
  661. {
  662.   text_section ();
  663.  
  664.   switch (TREE_CODE (type))
  665.     {
  666.     case RECORD_TYPE:
  667.     case UNION_TYPE:
  668.     case ENUMERAL_TYPE:
  669.       type = TYPE_MAIN_VARIANT (type);
  670.       /* Don't output a type twice.  */
  671.       if (TREE_ASM_WRITTEN (type))
  672.     return;
  673.  
  674.       TREE_ASM_WRITTEN (type) = 1;
  675. #if 0  /* This change, which ought to make better output,
  676.       makes the COFF assembler unhappy.  */
  677.       /* Before really doing anything, output types we want to refer to.  */
  678.       if (TREE_CODE (type) != ENUMERAL_TYPE)
  679.     sdbout_field_types (type);
  680. #endif
  681.  
  682.       sdbout_record_type_name (type);
  683.  
  684.       /* Output a structure type.  */
  685.       {
  686.     int size = int_size_in_bytes (type);
  687.     int member_scl;
  688.     tree tem;
  689.  
  690.     PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
  691.  
  692.     switch (TREE_CODE (type))
  693.       {
  694.       case UNION_TYPE:
  695.         PUT_SDB_SCL (C_UNTAG);
  696.         PUT_SDB_TYPE (T_UNION);
  697.         member_scl = C_MOU;
  698.         break;
  699.  
  700.       case RECORD_TYPE:
  701.         PUT_SDB_SCL (C_STRTAG);
  702.         PUT_SDB_TYPE (T_STRUCT);
  703.         member_scl = C_MOS;
  704.         break;
  705.  
  706.       case ENUMERAL_TYPE:
  707.         PUT_SDB_SCL (C_ENTAG);
  708.         PUT_SDB_TYPE (T_ENUM);
  709.         member_scl = C_MOE;
  710.         break;
  711.       }
  712.  
  713.     PUT_SDB_SIZE (size);
  714.     PUT_SDB_ENDEF;
  715.  
  716.     /* output the individual fields */
  717.  
  718.     if (TREE_CODE (type) == ENUMERAL_TYPE)
  719.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  720.         {
  721.           PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
  722.           PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
  723.           PUT_SDB_SCL (C_MOE);
  724.           PUT_SDB_TYPE (T_MOE);
  725.           PUT_SDB_ENDEF;
  726.         }
  727.       
  728.     else            /* record or union type */
  729.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  730.         /* Output the name, type, position (in bits), size (in bits)
  731.            of each field.  */
  732.         /* Omit here the nameless fields that are used to skip bits.  */
  733.         if (DECL_NAME (tem) != 0)
  734.           {
  735.         CONTIN;
  736.         PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (tem)));
  737.         if (TREE_PACKED (tem))
  738.           {
  739.             PUT_SDB_INT_VAL (DECL_OFFSET (tem));
  740.             PUT_SDB_SCL (C_FIELD);
  741.             sdbout_type (TREE_TYPE (tem));
  742.             PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem))
  743.                   * DECL_SIZE_UNIT (tem));
  744.           }
  745.         else
  746.           {
  747.             PUT_SDB_INT_VAL (DECL_OFFSET (tem) / BITS_PER_UNIT);
  748.             PUT_SDB_SCL (member_scl);
  749.             sdbout_type (TREE_TYPE (tem));
  750.           }
  751.         PUT_SDB_ENDEF;
  752.           }
  753.     /* output end of a structure,union, or enumeral definition */
  754.    
  755.     PUT_SDB_PLAIN_DEF ("eos");
  756.     PUT_SDB_INT_VAL (size);
  757.     PUT_SDB_SCL (C_EOS);
  758.     PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
  759.     PUT_SDB_SIZE (size);
  760.     PUT_SDB_ENDEF;
  761.     break;
  762.       }
  763.     }
  764. }
  765.  
  766. /* Output definitions of all parameters, referring when possible to the
  767.    place where the parameters were passed rather than the copies used
  768.    within the function.     This is done as part of starting the function.
  769.    PARMS is a chain of PARM_DECL nodes.  */
  770.  
  771. static void
  772. sdbout_parms (parms1)
  773.      tree parms1;
  774. {
  775.   tree type;
  776.   tree parms;
  777.  
  778.   for (parms = parms1; parms; parms = TREE_CHAIN (parms))
  779.     {
  780.       int current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  781.  
  782.       if (DECL_NAME (parms))
  783.     PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));
  784.       else
  785.     PUT_SDB_DEF (gen_fake_label ());
  786.  
  787.       if (GET_CODE (DECL_RTL (parms)) == REG
  788.       && REGNO (DECL_RTL (parms)) >= 0
  789.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  790.     type = DECL_ARG_TYPE (parms);
  791.       else
  792.     {
  793.       /* This is the case where the parm is passed as an int or double
  794.          and it is converted to a char, short or float and stored back
  795.          in the parmlist.  In this case, describe the parm
  796.          with the variable's declared type, and adjust the address
  797.          if the least significant bytes (which we are using) are not
  798.          the first ones.  */
  799. #ifdef BYTES_BIG_ENDIAN
  800.       if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  801.         current_sym_value +=
  802.           (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  803.            - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  804. #endif
  805.       if (GET_CODE (DECL_RTL (parms)) == MEM
  806.           && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  807.           && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
  808.           && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
  809.           == current_sym_value))
  810.         type = TREE_TYPE (parms);
  811.       else
  812.         {
  813.           current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  814.           type = DECL_ARG_TYPE (parms);
  815.         }
  816.     }
  817.      
  818.       PUT_SDB_INT_VAL (current_sym_value);
  819.       PUT_SDB_SCL (C_ARG);
  820.       PUT_SDB_TYPE (plain_type (type));
  821.       PUT_SDB_ENDEF;
  822.     }
  823. }
  824.  
  825. /* Output definitions, referring to registers,
  826.    of all the parms in PARMS which are stored in registers during the function.
  827.    PARMS is a chain of PARM_DECL nodes.
  828.    This is done as part of starting the function.  */
  829.  
  830. static void
  831. sdbout_reg_parms (parms)
  832.      tree parms;
  833. {
  834.   while (parms)
  835.     {
  836.       if (GET_CODE (DECL_RTL (parms)) == REG
  837.       && REGNO (DECL_RTL (parms)) >= 0
  838.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  839.     {
  840.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));
  841.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
  842.         PUT_SDB_SCL (C_REG);
  843.       PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
  844.       PUT_SDB_ENDEF;
  845.     }
  846.       else if (GET_CODE (DECL_RTL (parms)) == MEM
  847.            && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  848.            && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT)
  849.     {
  850.       int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
  851.       /* A parm declared char is really passed as an int,
  852.          so it occupies the least significant bytes.
  853.          On a big-endian machine those are not the low-numbered ones.  */
  854. #ifdef BYTES_BIG_ENDIAN
  855.       if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  856.         offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  857.                - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  858. #endif
  859.       if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset)
  860.         {
  861.           PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));          
  862.           PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)));
  863.           PUT_SDB_SCL (C_AUTO);
  864.           PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
  865.           PUT_SDB_ENDEF;
  866.         }
  867.     }
  868.       parms = TREE_CHAIN (parms);
  869.     }
  870. }
  871.  
  872. /* Describe the beginning of an internal block within a function.
  873.    Also output descriptions of variables defined in this block.
  874.  
  875.    N is the number of the block, by order of beginning, counting from 1,
  876.    and not counting the outermost (function top-level) block.
  877.    The blocks match the LET_STMTS in DECL_INITIAL (current_function_decl),
  878.    if the count starts at 0 for the outermost one.  */
  879.  
  880. void
  881. sdbout_begin_block (file, line, n)
  882.      FILE *file;
  883.      int line;
  884.      int n;
  885. {
  886.   tree decl = current_function_decl;
  887.   MAKE_LINE_SAFE (line);
  888.   PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
  889.   if (n == 1)
  890.     {
  891.       /* Include the outermost LET_STMT's variables in block 1.  */
  892.       next_block_number = 0;
  893.       do_block = 0;
  894.       sdbout_block (DECL_INITIAL (decl), DECL_ARGUMENTS (decl));
  895.     }
  896.   next_block_number = 0;
  897.   do_block = n;
  898.   sdbout_block (DECL_INITIAL (decl), DECL_ARGUMENTS (decl));
  899. }
  900.  
  901. /* Describe the end line-number of an internal block within a function.  */
  902.      
  903. void
  904. sdbout_end_block (file, line)
  905.      FILE *file;
  906.      int line;
  907. {
  908.   MAKE_LINE_SAFE (line);
  909.   PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
  910. }
  911.  
  912. /* Output sdb info for the current function name.
  913.    Called from assemble_function.  */
  914.  
  915. void
  916. sdbout_mark_begin_function ()
  917. {
  918.   sdbout_symbol (current_function_decl, 0);
  919. }
  920.  
  921. /* Called at beginning of function body (after prologue).
  922.    Record the function's starting line number, so we can output
  923.    relative line numbers for the other lines.
  924.    Describe beginning of outermost block.
  925.    Also describe the parameter list.  */
  926.  
  927. void
  928. sdbout_begin_function (line)
  929.      int line;
  930. {
  931.   sdb_begin_function_line = line - 1;
  932.   PUT_SDB_FUNCTION_START (line);
  933.   sdbout_parms (DECL_ARGUMENTS (current_function_decl));
  934.   sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
  935. }
  936.  
  937. /* Called at end of function (before epilogue).
  938.    Describe end of outermost block.  */
  939.  
  940. void
  941. sdbout_end_function (line)
  942.      int line;
  943. {
  944.   MAKE_LINE_SAFE (line);
  945.   PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
  946.  
  947.   /* Indicate we are between functions, for line-number output.  */
  948.   sdb_begin_function_line = 0;
  949. }
  950.  
  951. /* Output sdb info for the absolute end of a function.
  952.    Called after the epilogue is output.  */
  953.  
  954. void
  955. sdbout_end_epilogue ()
  956. {
  957.   char *name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
  958.   PUT_SDB_EPILOGUE_END (name);
  959. }
  960.  
  961. #endif /* SDB_DEBUGGING_INFO */
  962.